package com.dog.dao.impl;

import com.dog.dao.ContactPersonDAO;
import com.dog.model.ContactPerson;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;

/**
 * User: Kuttubek Aidaraliev
 * Date: 30.04.2010
 * Time: 13:22:57
 */
@Repository
public class ContactPersonDAOImpl extends DAOImpl<ContactPerson> implements ContactPersonDAO {

   @Autowired
   private SessionFactory sessionFactory;

   public ContactPersonDAOImpl(){
       super(ContactPerson.class);
   }

   @PostConstruct 
   public void initialize(){
       this.setSessionFactory(sessionFactory);
   }

    @Override
    public ContactPerson getByIdWithRoles(Long contactPersonId) {
        String sql = "select distinct contactPerson from ContactPerson as contactPerson " +
                " left join fetch contactPerson.roles" +
                " where contactPerson.id=?";
        return findUnique(sql, contactPersonId);
    }
}
